package com.itheima.demo02;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class Test01 {
    public static void main(String[] args) {
        //创建HasMap对象

        HashMap<Student,String> m = new HashMap<>();

        //创建学生对象
        Student s1 = new Student("张三",20);
        Student s2 = new Student("李四",21);
        Student s3 = new Student("王五",23);

        //添加籍贯
        m.put(s1,"北京");
        m.put(s2,"上海");
        m.put(s3,"江苏");

        Set<Student> keys = m.keySet();

        for (Student key : keys) {
            System.out.println(key + "=" + m.get(key));
        }

        System.out.println("===========================");

        Set<Map.Entry<Student, String>> entries = m.entrySet();

        entries.forEach(new Consumer<Map.Entry<Student, String>>() {
            @Override
            public void accept(Map.Entry<Student, String> studentStringEntry) {
                Student key = studentStringEntry.getKey();
                String value = studentStringEntry.getValue();
                System.out.println(key + "=" + value);
            }
        });
        System.out.println("===========================");

        m.forEach(new BiConsumer<Student, String>() {
            @Override
            public void accept(Student student, String value) {
                System.out.println(student + "=" + value);
            }
        });
    }
}
